<template>
  <div class="body">

    <div class="display">
      <GeminiScrollbar class="my-scroll-bar">
        <div class="main">
          <div class="Avatar"><el-avatar  :size="100" :src="userInfo.avatar"></el-avatar></div>
          <div><label class="name">{{userInfo.username}}</label></div>
          <div class="sex"><label class="nameId">&nbsp {{userInfo.gender == 1 ? '男' : '女'}} &nbsp</label>
            <label class="nameId">&nbsp {{userInfo.uid}} &nbsp</label>
          </div>
          <div>
            <label style="font-family: 'Kaiti SC'; font-size: 20px; font-weight: bold">{{userInfo.content}}</label>
          </div>
          <div class="contact">
            <div>
            </div>
          </div>
          <!-- 弹幕评论 -->

          <div class="Barrage">
            <template style="margin: 0 auto" v-if="update">
              <el-carousel :interval="4000" type="card" height="250px" id="carousel_container">
                <el-carousel-item v-for="(item, index) in comments"   id="carousel" >
                  <!--                名字  头像  评论  时间-->
                  <el-avatar :size="50" :src="getFriendAvatar(item.commentatorid).avatar"></el-avatar><br>
                  <span style="font-family: 'Kaiti SC'; font-size: 20px; font-weight: bolder">{{getFriendAvatar(item.commentatorid).username}}</span>
                  <h3 class="medium" >{{item.content}}</h3>
                  <span>{{item.createtime.split("T")[0]}}</span><br>
                  <el-popover
                    placement="top"
                    width="160"
                    v-model= visibles[index]
                    >
                    <p>确定删除吗？</p>
                    <div style="text-align: right; margin: 0">
                      <el-button type="primary" size="mini" @click="confirmDelete(item, index)">确定</el-button>
                    </div>
                    <el-button slot="reference" size="mini" style="margin-top: 5px; background-color: darkorange">删除</el-button>
                  </el-popover>
                </el-carousel-item>
              </el-carousel>
            </template>
          </div>
        </div>
      </GeminiScrollbar>
    </div>

  </div>
</template>

<script>
    export default {
        name: 'MyCard',
        props: ["friendList"],
        data () {
            return {
                // friendList: [],
                userInfo: null,
                comments: [],
                visibles: [],
                update: true
            }
        },
        created() {
            var that = this
            this.userInfo = JSON.parse(window.localStorage.getItem("userInfo"));
            // this.friendList = JSON.parse(window.localStorage.getItem("friendList"));

            console.log("friendList???")
            console.log(that.friendList)
            this.$http(this.$api.getMyComment, {uid: this.userInfo.uid}).then(res=>{
                that.comments = res.data
                console.log("?????????")
                console.log(this.comments)
                for(var i = 0; i < that.comments.length; i++){
                    that.visibles.push(false);
                }
            })
        },
        methods:{
            confirmDelete(item, index){
                var that = this
                this.visibles[index] = false
                this.$http(this.$api.deleteMyComment, {commentid: item.commentid}).then(res=>{
                    that.$emit("refresh")
                    // that.update = false
                    // that.$nextTick(() => {
                    //     that.update = true
                    // })
                })

            },
            getFriendAvatar(tagid){
                if(this.friendList === null){
                    return "#"
                }
                for(var i = 0; i < this.friendList.length; i++){
                    if(this.friendList[i].uid === tagid)
                      return this.friendList[i]
                }
            },
        }


    }
</script>

<style scoped>
  .body{
    /*background-color: #ff0000;*/
    background-image: url("../../images/3.jpg");
    background-repeat: no-repeat;
    background-position: center;
    color: #333;
    text-align: center;
    width: 100%;
    height: 100%;
    position: absolute;

  }
  .display{
    /*background-color: rgba(2, 0, 0, 0.1);*/
    margin: 0 auto;
    width: 85%;
    height: 85%;
    position: relative;
    top: 7.5%;
    /*opacity: 0.1;*/
  }
  .name{
    color: black;
    font-family: "Kaiti SC";
    font-weight: bolder;
    font-size: 22px;
  }
  .my-scroll-bar{
    height: 100%;
  }
  .Avatar{
    height: 100px;
    padding-top: 40px;
    padding-bottom: 15px;
  }
  .el-avater{
    position: relative;
    margin-top:40px;
  }
  .sex{
    margin: 15px auto;
    height: 22px;
    width: 100px;
    /*background-color: rgba(80, 80, 80, 0.5);*/
    text-align: center;
    border-radius: 3px;
    color: white;
  }
  .nameId{
    background-color: rgba(0, 0, 0, 0.4);
    font-family: 微软雅黑;
    font-size: 10px;
    border-radius: 3px;
  }
  .contact{
    margin: 20px auto;
  }
  .el-button--primary{
    color: white;
    font-size: 15px;
    padding: 8px 14px;
    background-color: rgba(0, 0, 0, 0.4);
    border: 0;
  }
  .Barrage{
    width: 85%;
    margin: 100px auto 0;
  }
  .Barrage_button{
    margin-bottom: 20px;
  }
  .el-carousel__item h3 {
    color: black;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }
  #carousel{
    margin: 0 auto!important;
    padding: 15px;
    background-color: #ebe7c2;
    opacity: 0.9;
    text-align: center;
  }
  .medium{
    line-height: 100px!important;
    font-size: 25px!important;
  }
  .el-carousel__item:nth-child(2n) {
    width: 45%;
    background-color: white;
    opacity: 0.9;
    border-radius: 10px;
  }

  .el-carousel__item:nth-child(2n+1) {
    width: 45%;
    background-color: white;
    opacity: 0.9;
    border-radius: 10px;
  }

</style>
